#/bin/sh

CC      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc
LD      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-ld
AR      := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-ar
OBJCOPY := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-objcopy
OBJDUMP := /opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-objdump

INCLUDEDIR 	:= $(shell pwd)/include \
               -I$(shell pwd)/board/tq2416 \
               -I$(shell pwd)/fs
CFLAGS 		:= -Wall -Os -fno-builtin -nostdlib
CPPFLAGS   	:= -I$(INCLUDEDIR)
LDFLAGS 		:= -L /opt/CodeSourcery/Sourcery_G++_Lite/lib/gcc/arm-none-linux-gnueabi/4.5.2/armv4t -lgcc

export 	CC AR LD OBJCOPY OBJDUMP INCLUDEDIR CFLAGS CPPFLAGS

objs := arch/arm/kernel/arm926ej.o \
        arch/arm/kernel/os_cpu_a.o \
        arch/arm/kernel/trap.o \
        arch/arm/kernel/mmu.o \
        arch/arm/kernel/init.o \
        arch/arm/kernel/nand_bootcp.o \
        arch/arm/kernel/boot.o \
        arch/arm/lib/div64.o \
        libc/stdio/vsprinf.o \
        libc/stdio/sprintf.o \
        libc/string.o \
        libc/ctype.o \
        libc/shell.o \
        libc/command.o \
        board/tq2416/s3c2416.o \
        board/tq2416/tq2416.o \
        board/tq2416/s3c2416_usbdev.o \
        board/tq2416/s3c2416_clock.o \
        board/tq2416/s3c2416_int.o \
        board/tq2416/s3c2416_ddram.o \
        board/tq2416/s3c2416_uart0.o \
        board/tq2416/s3c2416_nand.o \
        board/tq2416/s3c2416_timer4.o \
        board/tq2416/s3c2416_key.o \
        board/tq2416/s3c2416_dm9000.o
        
all: simpleboot.elf simpleboot.bin simpleboot.dis brust

simpleboot.elf: $(objs)
	${LD} -Tsimpleboot.lds  $^ $(LDFLAGS) -o simpleboot.elf

simpleboot.dis:simpleboot.elf
	${OBJDUMP} -D simpleboot.elf > simpleboot.dis

simpleboot.bin: simpleboot.elf
	${OBJCOPY} -O binary -S simpleboot.elf $@

brust: simpleboot.bin
	rm /mnt/hgfs/Image/u-boot.bin -rf
	cp simpleboot.bin /mnt/hgfs/Image/u-boot.bin -rf
	
%.o:%.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

%.o:%.S
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

clean:
	rm -f *.bin *.elf *.dis *.o *~ $(objs)
	
install:simpleboot.bin
	
	cp *.bin /mnt/hgfs/Image/u-boot.bin
